# Definition for singly-linked list.
class ListNode:
    def __init__(self, x):
        self.val = x
        self.next = None

class Solution:
    def deleteDuplicates(self, head):
        """
        :type head: ListNode
        :rtype: ListNode
        """
        # p_head = cur = ListNode(0)
        # cur.next = head
        # cur = cur.next
        # while head !=None:
        #     if head.val != cur.val:
        #         cur.next = head
        #         head =head.next
        #         cur = cur.next
        #     else:
        #         cur.next = head.next
        #         head = head.next
        #
        #
        #     # print(head.val)
        #     # print(cur.val)
        # return p_head.next
        if not head:
            return None
        p = ListNode(-1)
        l = p
        f = p.next
        while f:
            if f.val == l.val:
                v = f.val
                while f and f.val == v:
                    f = f.next
                l.next = f
                l = f
                f = f.next
            else:
                l = l.next
                f = f.next
        return p.next


l1 = ListNode(1)
l1.next = ListNode(1)
l1.next.next = ListNode(2)
l1.next.next.next = ListNode(2)
# l1.next.next.next.next = ListNode(3)



m = Solution()
s = m.deleteDuplicates(l1)
while s!=None:
    print(s.val)
    s = s.next

#一个指针的方法
# class Solution(object):
#     def deleteDuplicates(self, head):
#         """
#         :type head: ListNode
#         :rtype: ListNode
#         """
#         cur = head
#         while cur:
#             while cur.next and cur.val == cur.next.val:
#                 cur.next = cur.next.next
#             cur = cur.next
#         return head